
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-theme', 'bootstrap-daterangepicker'], function ($, undefined, Backend, Table, Form, Echarts) {
    var Controller = {
        index: function () {
            $("#reportrange").daterangepicker({
                timePicker: true, // 启用时间选择
                timePickerSeconds: true, // 启用秒选择
                autoUpdateInput: false, // 自动更新输入框值
                locale: {
                    format: 'YYYY-MM-DD HH:mm:ss', // 日期时间格式
                    customRangeLabel: "自定义",
                    applyLabel: "确认",
                    cancelLabel: "重置"
                },
                ranges: {
                    '今天': [Moment().startOf('day'), Moment().endOf('day')],
                    '昨天': [Moment().subtract(1, 'days').startOf('day'), Moment().subtract(1, 'days').endOf('day')],
                    '最近7天': [Moment().subtract(6, 'days').startOf('day'), Moment().endOf('day')],
                    '最近30天': [Moment().subtract(29, 'days').startOf('day'), Moment().endOf('day')],
                    '本月': [Moment().startOf('month'), Moment().endOf('month')],
                    '上月': [Moment().subtract(1, 'month').startOf('month'), Moment().subtract(1, 'month').endOf('month')]
                }
            });
            $('#reportrange span').html(Moment().startOf('day').format('YYYY-MM-DD HH:mm:ss') + ' - ' + Moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'));
            // 监听选择事件
            $('#reportrange').on('apply.daterangepicker', function (ev, picker) {
                console.log(picker);
                $('#reportrange span').html(picker.startDate.format('YYYY-MM-DD HH:mm:ss') + ' - ' + picker.endDate.format('YYYY-MM-DD HH:mm:ss'));
                // $(this).val(picker.startDate.format('YYYY-MM-DD HH:mm:ss') + ' - ' + picker.endDate.format('YYYY-MM-DD HH:mm:ss'));
            });

            $('#reportrange').on('cancel.daterangepicker', function (ev, picker) {
                console.log(picker);

                $('#reportrange span').html(Moment().startOf('day').format('YYYY-MM-DD HH:mm:ss') + ' - ' + Moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'));
            });
            //订单
            var myOrderChart = Echarts.init(document.getElementById('order'));
            var orderOption = {

                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['推广订单金额(元)', '支付佣金(元)', '订单数','成交客户数','绑定客户数','邀请下级数'],
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '10%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ['02-02', '02-03', '02-04', '02-05', '02-06', '02-07', '02-08','02-02', '02-03', '02-04', '02-05', '02-06', '02-07', '02-08','02-02', '02-03', '02-04', '02-05', '02-06', '02-07', '02-08']
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '推广订单金额(元)',
                        type: 'line',
                        data: [120, 132, 101, 134, 90, 230, 210,120, 132, 101, 134, 90, 230, 210,120, 132, 101, 134, 90, 230, 210],
                        itemStyle: {
                            color: '#dcab83'
                        }
                    },
                    {
                        name: '支付佣金(元)',
                        type: 'line',
                        data: [300, 500, 400, 450, 474, 480, 410,300, 500, 400, 450, 474, 480, 410,300, 500, 400, 450, 474, 480, 410],
                        itemStyle: {
                            color: '#e8cd8c'
                        }
                    },
                    {
                        name: '订单数',
                        type: 'line',
                        data: [400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650],
                        itemStyle: {
                            color: '#da7a5f'
                        }
                    },
                    {
                        name: '成交客户数',
                        type: 'line',
                        data: [400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650],
                        itemStyle: {
                            color: '#da7a5f'
                        }
                    },
                    {
                        name: '绑定客户数',
                        type: 'line',
                        data: [400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650],
                        itemStyle: {
                            color: '#da7a5f'
                        }
                    },
                    {
                        name: '邀请下级数',
                        type: 'line',
                        data: [400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650,400, 600, 430, 480, 500, 550, 650],
                        itemStyle: {
                            color: '#da7a5f'
                        }
                    },

                ]
            };
            myOrderChart.setOption(orderOption);
        }
    };
    return Controller;
});